import Vue from 'vue'
import App from './App.vue'
import router from './router'
import vuetify from './plugins/vuetify';
import vueTouch from 'kim-vue-touch';
import Msg from './tools/msg'
import http from './tools/http'
import filter from './tools/filters'
import utils from './tools/utils'
import 'normalize.css'

Vue.config.productionTip = false

Vue.use(Msg)
Vue.use(vueTouch)
Vue.mixin(filter)
Vue.prototype.Util = utils
Vue.prototype.Http = http

/**
 * 自定义指令（按钮权限）
 */
Vue.directive('ButtonPermission', {
  // 当被绑定的元素插入到 DOM 中时……
  inserted: function (el, binding) {
    // 取值
    const ButtonName = binding.value.ButtonName
    const stroage = typeof sessionStorage.getItem('LOGIN_INFO') == 'string' && sessionStorage.getItem('LOGIN_INFO')
      ? JSON.parse(sessionStorage.getItem('LOGIN_INFO')).button : ""
    if (!stroage) {
      return
    }
    Object.values(stroage).forEach(item => {
      item.forEach(button => {
        if (button.buttonName == ButtonName) {
          // 判断该按钮权限 true允许   false不允许
          let isDisabled = button.isHide
          // 聚焦元素
          if (!isDisabled) {
            el.disabled = true
            el.classList.add('is-hide')
          }
        }
      })
    })
  }
})

const app = new Vue({
  vuetify,
  router,
  render: h => h(App)
}).$mount('#app')

export default app